// 导入模块
import { _decorator, Component, Label } from 'cc';
const { ccclass, property } = _decorator;

/**
 * UI管理器，负责游戏界面的控制和更新
 */
@ccclass('UIManager')
export class UIManager extends Component {
    /**
     * 分数显示标签
     */
    @property(Label)
    public scoreLabel: Label | null = null;

    /**
     * 生命值显示标签
     */
    @property(Label)
    public healthLabel: Label | null = null;

    /**
     * 当前分数
     */
    private _score: number = 0;
    /**
     * 当前生命值
     */
    private _health: number = 100;

    /**
     * 初始化UI
     */
    public init(): void {
        this.updateScore();
        this.updateHealth();
    }

    /**
     * 更新分数显示
     */
    public updateScore(): void {
        if (this.scoreLabel) {
            this.scoreLabel.string = `Score: ${this._score}`;
        }
    }

    /**
     * 更新生命值显示
     */
    public updateHealth(): void {
        if (this.healthLabel) {
            this.healthLabel.string = `Health: ${this._health}`;
        }
    }

    /**
     * 增加分数
     * @param value 增加的分数值
     */
    public addScore(value: number): void {
        this._score += value;
        this.updateScore();
    }

    /**
     * 更新生命值
     * @param value 生命值变化量
     */
    public changeHealth(value: number): void {
        this._health = Math.max(0, this._health + value);
        this.updateHealth();
    }

    /**
     * 重置UI状态
     */
    public reset(): void {
        this._score = 0;
        this._health = 100;
        this.updateScore();
        this.updateHealth();
    }

    /**
     * 渲染UI
     */
    public render(): void {
        this.updateScore();
        this.updateHealth();
    }
}
